home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / gfx / board / Graffiti_lib.lha / Graffiti / ganim.c < prev    next >
C/C++ Source or Header  |  1997-03-29  |  4KB  |  204 lines

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. #include <exec/memory.h>
  6. #include <dos/dos.h>
  7. #include <devices/timer.h>
  8. #include <utility/hooks.h>
  9.  
  10. #include "graffiti.h"
  11.  
  12. #include <proto/exec.h>
  13. #include <proto/graphics.h>
  14. #include <proto/timer.h>
  15.  
  16. void __regargs __chkabort (void);
  17. void __regargs __chkabort (void)
  18. {
  19. }
  20.  
  21. extern WORD fastsin (WORD, WORD);
  22. extern WORD fastcos (WORD, WORD);
  23.  
  24. struct Library * TimerBase;
  25. struct timerequest * TimerIO;
  26.  
  27. int _STI_205_Timer (void)
  28. {
  29.     if (!(TimerIO = AllocMem (sizeof (struct timerequest), MEMF_PUBLIC|MEMF_CLEAR)) )
  30.     return 1;
  31.  
  32.     if (OpenDevice (TIMERNAME, UNIT_MICROHZ, (struct IORequest *)TimerIO, 0))
  33.     {
  34.     FreeMem (TimerIO, sizeof (struct timerequest));
  35.     return 1;
  36.     }
  37.  
  38.     TimerBase = (struct Library *)TimerIO->tr_node.io_Device;
  39.  
  40.     return 0;
  41. }
  42.  
  43. void _STD_205_Device (void)
  44. {
  45.     CloseDevice ((struct IORequest *)TimerIO);
  46. }
  47.  
  48. #define DEMO_GENELLIPSE     0
  49. #define DEMO_ROTATELINE     0
  50. #define DEMO_ROTATEBOX        1
  51.  
  52. int main (int argc, char ** argv)
  53. {
  54.     struct GraffitiHandle * gh;
  55.     struct IntuiMessage * im;
  56.     ULONG width;
  57.     int mode, fps;
  58.     struct timeval time1, time2;
  59.     char string[32];
  60.     int frame, sec, white;
  61.  
  62. #if DEMO_GENELLIPSE
  63.     int x, y, rx, ry, angle, col;
  64. #endif
  65. #if DEMO_ROTATELINE
  66.     int x, y, x1, y1, x2, y2, angle;
  67. #endif
  68. #if DEMO_ROTATEBOX
  69.     int x, y, x1, y1, x2, y2, x3, y3, angle;
  70. #endif
  71.  
  72.     /* Init card */
  73.     if (argc == 1)
  74.     {
  75.     gh = Graffiti_Init (
  76.         GTI_BUFFER, GRAFFITI_BUFFER_DOUBLE,
  77.         TAG_END);
  78.     }
  79.     else
  80.     {
  81.     mode = atoi (argv[1]);
  82.  
  83.     if (mode < 0 || mode > 1)
  84.     {
  85.         fprintf (stderr, "Mode must be between 0 or 1\n");
  86.         return 10;
  87.     }
  88.  
  89.     gh = Graffiti_Init (
  90.         GTI_RESOLUTION, mode ? GRAFFITI_RES_640 : GRAFFITI_RES_320,
  91.         GTI_BUFFER, GRAFFITI_BUFFER_DOUBLE,
  92.         TAG_END);
  93.     }
  94.  
  95.     Graffiti_InstallPalette3 (gh);
  96.  
  97.     Graffiti_GetAttr (gh, GTI_WIDTH, &width);
  98.  
  99.     frame = 0;
  100.  
  101.     white = Graffiti_FindBestMatch (gh, 255,255,255);
  102.  
  103. #if DEMO_GENELLIPSE
  104.     x = width/2;
  105.     y = 128;
  106.     angle = 0;
  107.     col = 160;
  108.     rx = 80;
  109.     ry = 20;
  110. #endif
  111. #if DEMO_ROTATELINE
  112.     x = width/2;
  113.     y = 128;
  114.     angle = 0;
  115.     x1 = 100;
  116.     y1 = 0;
  117.     Graffiti_SetFG (gh, white);
  118. #endif
  119. #if DEMO_ROTATEBOX
  120.     x = width/2;
  121.     y = 128;
  122.     angle = 0;
  123.     x1 = 100;
  124.     y1 = 0;
  125.     Graffiti_SetFG (gh, white);
  126. #endif
  127.  
  128.     sec = 0;
  129.     fps = 0;
  130.  
  131.     GetSysTime (&time1);
  132.  
  133.     for (;;)
  134.     {
  135.     if ((im = Graffiti_CheckEvent (gh)))
  136.     {
  137.         ReplyMsg ((struct Message *)im);
  138.         break;
  139.     }
  140.  
  141.     Graffiti_UseNextBuffer (gh);
  142.  
  143. #if DEMO_GENELLIPSE
  144.     /* about 16fps */
  145.     Graffiti_SetFG (gh, col);
  146.     Graffiti_FillGenEllipse (gh, x, y, rx, ry, angle);
  147.     angle += 128;
  148.     col ++;
  149. #endif
  150.  
  151. #if DEMO_ROTATELINE
  152.     /* about 24fps */
  153.     x2 = fastcos (angle, x1);
  154.     y2 = fastsin (angle, x1);
  155.  
  156.     /* printf ("vec=%d/%d\n", x2, y2); */
  157.  
  158.     Graffiti_DrawLine (gh, x-x2,y-y2, x+x2,y+y2);
  159.     Graffiti_DrawLine (gh, x-y2,y+x2, x+y2,y-x2);
  160.  
  161.     angle += 128;
  162. #endif
  163.  
  164. #if DEMO_ROTATEBOX
  165.     /* about 24fps */
  166.     x2 = fastcos (angle, x1);
  167.     y2 = fastsin (angle, x1);
  168.     x3 = y2;
  169.     y3 = -x2;
  170.  
  171.     /* printf ("vec=%d/%d\n", x2, y2); */
  172.  
  173.     Graffiti_DrawLine (gh, x+x2,y+y2, x+x3,y+y3);
  174.     Graffiti_DrawLine (gh, x+x3,y+y3, x-x2,y-y2);
  175.     Graffiti_DrawLine (gh, x-x2,y-y2, x-x3,y-y3);
  176.     Graffiti_DrawLine (gh, x-x3,y-y3, x+x2,y+y2);
  177.  
  178.     angle += 128;
  179. #endif
  180.  
  181.     /* Time the anim */
  182.     frame ++;
  183.  
  184.     GetSysTime (&time2);
  185.     SubTime (&time2, &time1);
  186.  
  187.     sec = time2.tv_secs * 1000 + time2.tv_micro / 1000;
  188.  
  189.     if (sec)
  190.         fps = frame * 1000000 / sec;
  191.  
  192.     sprintf (string, "%4d %3d.%03d", frame, fps/1000, fps%1000);
  193.     Graffiti_SetFG (gh, white);
  194.     Graffiti_DrawText (gh, width-120, 230, string, 12);
  195.  
  196.     Graffiti_ShowNextBuffer (gh);
  197.     }
  198.  
  199.     /* Exit demo */
  200.     Graffiti_Exit (gh);
  201.  
  202.     printf ("%d frames\n", frame);
  203. } /* main */
  204.